Column

Sales by department

cart = read_csv("./data/instacart_train_data.csv.zip")
## Parsed with column specification:
## cols(
##   order_id = col_integer(),
##   product_id = col_integer(),
##   add_to_cart_order = col_integer(),
##   reordered = col_integer(),
##   user_id = col_integer(),
##   eval_set = col_character(),
##   order_number = col_integer(),
##   order_dow = col_integer(),
##   order_hour_of_day = col_integer(),
##   days_since_prior_order = col_integer(),
##   product_name = col_character(),
##   aisle_id = col_integer(),
##   department_id = col_integer(),
##   aisle = col_character(),
##   department = col_character()
## )
cart%>%
  filter(department != "missing")%>%
  group_by(department)%>%
  mutate(sales = n())%>%
  distinct(department,sales)%>%
  ungroup(department)%>%
  mutate(department = fct_reorder(as.factor(department),sales))%>%
  mutate(hover=str_c(department," Sales:$",sales))%>%
  plot_ly(x = ~department, y = ~sales, type = "bar", color=~department, text=~hover, alpha = 0.5)
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors

Column

“Busy days” in a week

cart%>%
  filter(department != "missing")%>%
  mutate(order_dow = order_dow+1)%>%
  group_by(order_dow, department)%>%
  mutate(sales = n())%>%
  plot_ly(x=~order_dow, y=~sales, type = "scatter", color = ~department, mode = "line")
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors
## A line object has been specified, but lines is not in the mode
## Adding lines to the mode...
## A line object has been specified, but lines is not in the mode
## Adding lines to the mode...
## A line object has been specified, but lines is not in the mode
## Adding lines to the mode...
## A line object has been specified, but lines is not in the mode
## Adding lines to the mode...
## A line object has been specified, but lines is not in the mode
## Adding lines to the mode...
## A line object has been specified, but lines is not in the mode
## Adding lines to the mode...
## A line object has been specified, but lines is not in the mode
## Adding lines to the mode...
## A line object has been specified, but lines is not in the mode
## Adding lines to the mode...
## A line object has been specified, but lines is not in the mode
## Adding lines to the mode...
## A line object has been specified, but lines is not in the mode
## Adding lines to the mode...
## A line object has been specified, but lines is not in the mode
## Adding lines to the mode...
## A line object has been specified, but lines is not in the mode
## Adding lines to the mode...
## A line object has been specified, but lines is not in the mode
## Adding lines to the mode...
## A line object has been specified, but lines is not in the mode
## Adding lines to the mode...
## A line object has been specified, but lines is not in the mode
## Adding lines to the mode...
## A line object has been specified, but lines is not in the mode
## Adding lines to the mode...
## A line object has been specified, but lines is not in the mode
## Adding lines to the mode...
## A line object has been specified, but lines is not in the mode
## Adding lines to the mode...
## A line object has been specified, but lines is not in the mode
## Adding lines to the mode...
## A line object has been specified, but lines is not in the mode
## Adding lines to the mode...

“Busy time” by department

cart%>%
  filter(department != "missing")%>%
  group_by(department)%>%
  mutate(median_hour=median(order_hour_of_day))%>%
  ungroup(department)%>%
  mutate(department = fct_reorder(department,median_hour))%>%
  plot_ly(x = ~department, y = ~order_hour_of_day, type = "box", color=~department, alpha = 0.5)
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors